<template>
	<view class="list-view">
		<view class="top-bar">
			<uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" :title="title">
			</uni-navbar>
		</view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题" labelAlign="left" label-width="190">
						<u-input v-model="listQuery.title" type="text" placeholder="请输入标题" />
					</u-form-item>
					<u-form-item class="form-item" label="届次" labelAlign="left" label-width="190">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次"
							@click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm">
						</u-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<view class="search-view">
			<u-search class="search-input" v-model="listQuery.title" :show-action="false"
				@search="search" @custom="show = !show"></u-search>
			<!-- <view class="" style="display: flex;align-items: center;">
				<image style="width: 26upx;height: 30upx;" src="../../../static/sx.png" mode=""></image>
				<text style="font-size: 14px;color: #666666;padding-left: 10upx;">筛选</text>
			</view> -->
		</view>
		
		
		<u-tabs v-if="tabShow" class="uTabs" :list="tabsList" :is-scroll="false" v-model="tabsCurrent" @change="tabsChange"></u-tabs>

		<view class="list-box">
			<view class="list-info_01" v-for="(item, index) of ysList" :key="item.id" >
				<view class="info-title" @click="navTo(item)">{{ item.title }}</view>
				<view class="info-btm" @click="navTo(item)">
					<view class="btm-left clamp">
						<!-- <text class="left-name" >{{ item.createByName }}</text> -->
						<text class="left-time">{{ item.submitTime }}</text>
						<text class="left-time" style="padding-left: 20rpx;" >{{ item.submitName }}</text>
					</view>
					<!-- <view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">
							{{ statusMap[item.nodeStatus] }}</view>
					</view> -->
				</view>
				
				<view class="changeBtnList">
					
					<view class="changeBtnListItem" @tap="intitle('msly',item)" v-if="tabsCurrent == '1'">
						码上留言
					</view>
					
					<view class="changeBtnListItem" @tap="intitle('msgk',item)" v-if="tabsCurrent == '1'">
						码上公开
					</view>
					
					<view class="changeBtnListItem" @tap="intitle('sc',item)" v-if="tabsCurrent == '2' && isSC">
						审查
					</view>
					
					<!-- <view class="changeBtnListItem" @tap="intitle('gs',item)" v-if="tabsCurrent == '3'">
						公示
					</view> -->
					
					<view class="changeBtnListItem inkssqdy" @tap="intitle('xg',item)" v-if="tabsCurrent == '1'">
						修改
					</view>
				
				</view>
			</view>
			
			
			
		</view>
		
		
		<view class="noMessage" v-if="isNoMessage">
			<view class="noMessageImg">
				<image src="@/static/result-img/no-data.png" mode=""></image>
			</view>
			<!-- <view class="noMessageText">
				暂无内容
			</view> -->
		</view> 
		
		<u-loadmore v-if="isno" :status="loading" />
		<image src="/static/img/icon_tianbao.png" mode="widthFix" class="tianbao" @click="editTo"
			v-if="$sysBtns(flag + '_add')"></image>
		<u-back-top :scroll-top="scrollTop" top="150" style="right: 40rpx; bottom: 50rpx"></u-back-top>

		<view v-if="false && flag"></view>


		<view class="bottomBtn">
			<view class="bottomBtnInfo" @tap="yttjTap">
				<image src="../../../../static/yttj2222.png" mode=""></image>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				isSC:false,
				isNoMessage:false,
				isno:false,
				tabShow:false,
				scrollTop: 0,
				show: false,
				tabsCurrent: 0,
				tabsList: [{
					name: '我的议题',
				},
				{
					name: '全部议题',
				},
				{
					name: '议题审查',
				},
				{
					name: '待公示',
				},
				{
					name: '议题退回',
				}],
				colorMap: {
					0: '#303133',
					1: '#19be6b',
					2: '#ff9900',
					3: '#0099ff',
					4: '#ff3333'
				},
				statusMap: {
					0: '草稿',
					1: '待初审',
					2: '待审核',
					3: '通过',
					4: '不通过'
				},
				nodeStatus: -1,
				title: '人大会议',
				jieci: '',
				jcShow: false,
				jcList: [],
				flag: 'huiyi',
				dutiesList: [],
				listQuery:{
					title:'',
					currentUserId:'',
					clientCode:'370782',
					dbzjDeptId:'',
					dataRange:'',
					isSource:'',
					isNode:'',
					isReview:'',
					flagNew:'',
					pageSize:'10',
					pageNum:'1'
				},
				ysList:[],
				perform: {
					ciId: '',
					jieId: '',
					status: '1',
					wyhdz: '',
					nodeStatus: '',
					module: '1',
					title: ''
				},
				loading: 'nomore'
			}; 
		},
		onLoad(option) {
			this.loadLogin()
		},
		onShow() {
			if(this.$roleCodes('weiyuan')){
				this.tabsList = [{
					name: '我的议题',
				}]
				this.tabShow = true
			}else{
				this.tabShow = true
			}
			
			if(this.$roleCodes('sys_manager')){
				
				this.isSC = true
			}else{
				this.isSC = false
			}
			
			
			
			
			this.listQuery.pageNum = '1'
			this.getList(this.tabsCurrent)
		},
		onPullDownRefresh() {
			this.getList(this.tabsCurrent)
		},
		onReachBottom() {
			if(!this.isno && !this.isNoMessage){
				this.getAlllist(this.tabsCurrent)
			}
		},
		onPageScroll(res) {
			this.scrollTop = res.scrollTop;
		},
		computed: {
			...mapState(['userInfo']),
			listQueryTitle(){
				return this.listQuery.title
			}
		},
		watch:{
			listQueryTitle(e,v){
				this.getList(this.tabsCurrent)
			}
		},
			
		methods: {
			intitle(e,v){
				if(e == 'msly'){
					uni.navigateTo({
						url:'/pagesB/msysDB/msjz/dzplDetail4/dzplDetail4?type=1&id=' + v.id 
					})
				}
				
				if(e == 'msgk'){
					uni.navigateTo({
						url:'/pagesB/msysDB/msjz/dzplDetail4/dzplDetail4?type=2&id=' + v.id
					})
				}

				if(e == 'sc'){
					uni.navigateTo({
						url:'../xq/xq?type=1&id=' + v.id
					})
				}
				
				if(e == 'gs'){
					uni.navigateTo({
						url:'../xq/xq?type=2&id=' + v.id
					})
				}
				
				
				if(e == 'xg'){
					uni.navigateTo({
						url:'../wdyt2/wdyt2?id=' + v.id
					})
				}
			},
			yttjTap(){
				uni.navigateTo({
					url:'../wdyt/wdyt'
				})
			},
			getList(e = 0){
				let that = this
				this.isno = false
				this.isNoMessage = false
				let url = '/msIssueInfo/list';
				let a = JSON.parse(JSON.stringify(that.listQuery))
				if(e == 0){
					a.isNode = ''
					a.isReview = ''
					a.flagNew = '1'
				}
				
				if(e == 1){
					a.isNode = ''
					a.isReview = ''
				}
				
				if(e == 2){
					a.isNode = '2'
					a.isReview = '0'
				}
				
				if(e == 3){
					a.isNode = '3'
					a.isReview = '0'
				}
				
				if(e == 4){
					a.isNode = '21'
					a.isReview = '0'
				}
				
				
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						if(res.data && res.data.records.length !== 0){
							that.ysList = res.data.records
						}else{
							that.ysList = []
							that.isNoMessage = true
						}
					}
					
				});
			},
			
			getAlllist(e = 0){
				let that = this
				let url = '/msIssueInfo/list';
				let a = JSON.parse(JSON.stringify(that.listQuery))
				
				if(e == 0){
					a.isNode = ''
					a.isReview = ''
					a.flagNew = '1'
				}
				
				if(e == 1){
					a.isNode = ''
					a.isReview = ''
				}
				
				if(e == 2){
					a.isNode = '2'
					a.isReview = '0'
				}
				
				if(e == 3){
					a.isNode = '3'
					a.isReview = '0'
				}
				
				if(e == 4){
					a.isNode = '21'
					a.isReview = '0'
				}
				
				
				a.pageNum++
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						if(res.data.records.length !== 0){
							that.listQuery.pageNum++
							that.ysList.push(...res.data.records)
						}else{
							that.isno = true
							
						}
					}
					
				});
			},
			loadLogin() {
				if (this.userInfo.sysUser) {
					this.clientCode = this.userInfo.sysUser.clientCode;
					this.userId = this.userInfo.sysUser.id;
					this.roleCodes = this.userInfo.roleCodes.join(',');
					
					if(this.$roleCodes('zc_admin')){
						this.listQuery.currentUserId = ''
					}else{
						this.listQuery.currentUserId = this.userId
					}
					
					
					
					this.pageNum = 1;
					this.pageSize = 10;
				} else {
					this.$logout();
				}
			},
			loadData(type = 'add') {
				if (this.loading == 'loading') {
					return false;
				}
				if (type == 'add') {
					if (this.loading == 'nomore') {
						return false;
					}
					this.loading = 'loading';
				} else {
					this.loading = 'loading';
				}
				if (type != 'add') {
					this.pageNum = 1;
				}
				if (this.perform.nodeStatus == '-1') {
					this.perform.nodeStatus = '';
				}
				let data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					currentUserId: this.userId,
					clientCode: this.clientCode,
					roleCodes: this.roleCodes,
					perform: this.perform
				};
				this.$request('/perform/myList', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.dutiesList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' :
					'nomore';
					this.pageNum = this.pageNum + 1;
					this.dutiesList = this.dutiesList.concat(res.data.records);
					this.loaded = true;
					if (this.dutiesList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			},
			loadDict(type) {
				this.$request('/system/sys-dict/dictList', {
					clientCode: this.clientCode,
					sysDict: {
						dictType: type
					}
				}).then((res) => {
					this.tabsList.push({
						name: '所有',
						value: '-1'
					});
					res.data.forEach((item) => {
						this.tabsList.push({
							name: item.dictName,
							value: item.dictValue
						});
					});
				});
			},
			tabsChange(index) {
				this.tabsCurrent = index;
				this.getList(index)
				// this.type(this.tabsList[index].value);
			},
			jcConfirm(e) {
				this.jieci = e[0].label + e[1].label;
				this.perform.jieId = e[0].value;
				this.perform.ciId = e[1].value;
			},
			filter() {
				this.show = false;
				this.loadData('refresh');
			},
			resert() {
				this.show = false;
				this.perform.title = '';
				this.jieci = '';
				this.perform.jieId = '';
				this.perform.ciId = '';
				this.loadData('refresh');
			},
			search(e) {
				this.perform.title = e;
				this.listQuery.pageNum = '1'
				this.loadData('refresh');
			},
			type(e) {
				this.nodeStatus = e;
				this.perform.nodeStatus = e.toString();
				this.loadData('refresh');
			},
			jieciData() {
				let data = {
					clientCode: this.clientCode,
					jieCi: {
						pid: ''
					}
				};
				this.$request('/jie-ci/list', data).then((res) => {
					this.jcList = [];
					let jieArr = [];
					let ciArr = [];
					res.data.forEach((item) => {
						data.jieCi.pid = item.id;
						this.$request('/jie-ci/list', data).then((res) => {
							ciArr = [];
							res.data.forEach((key) => {
								ciArr.push({
									value: key.id,
									label: key.name
								});
							});
							this.jcList.push({
								value: item.id,
								label: item.name,
								children: ciArr
							});
						});
					});
				});
			},
			navTo(item) {
				let that = this
				uni.navigateTo({
					url:'../xq/xq?id=' + item.id + '&type=' + that.tabsCurrent
				})
			},
			editTo(item) {
				uni.navigateTo({
					url: '/pagesA/duties/add?flag=' + this.flag + '&code=' + this.perform.module + '&name=' + this
						.title
				});
			}
		}
	};
</script>

<style  lang="scss" scoped>
	.uTabs {
		min-height: 88rpx;
	}

	.list-box {
		padding: 0 30rpx;
		background-color: #fff;
	}

	.tianbao {
		display: block;
		position: fixed;
		right: 40rpx;
		bottom: 170rpx;
		width: 160rpx;
		height: 160rpx;
	}

	.filter-box {
		position: fixed;
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;
		z-index: 998;
		background-color: #fff;
	}

	.form-box {
		.form-item {
			@include mp-flex;
			border-bottom: 20rpx solid #f5f7fa;
		}
	}

	.fiexd-btm {
		position: static;
		padding: 30rpx;
	}

	.bottomBtn {
		position: fixed;
		bottom: 400upx;
		right: 20upx;
		width: 100upx;
		height: 100upx;
		text-align: center;
		// background-color: red;
		border-radius: 50%;
		padding: 10upx;
		color: #fff;

		.bottomBtnInfo {
			position: relative;
			right: 30upx;
			image{
				width: 124upx;
				height: 124upx;
			}
		}
	}
	
	.noMessage{
		background-color: #f6f7fb;
		display: flex;
		justify-content: center;
		justify-items: center;
		flex-direction:column;
		margin-top: 80upx;
		.noMessageImg{
			text-align: -webkit-center;
			image{
				width: 676rpx;
				    height: 352rpx;
			}
		}
		
		.noMessageText{
			margin-top: 30upx;
			font-size: 40upx;
			color: #666666;
			text-align: center;
		}
	}
	
	.u-load-more-wrap{
		background: none !important;
	}
	
	.u-more-text{
		background: none !important;
	}
	
	
	.changeBtnList{
		display: flex;
		align-items: center;
		justify-content: flex-end;
		flex-wrap: wrap;
		margin-top: 20upx;
		.changeBtnListItem{
			font-size: 14px;
			color: #333333;
			border-radius: 50upx;
			padding: 10upx 20upx;
			border: 1upx solid #999999;
			margin: 0 10upx;
		}
	}
	
	.inkssqdy{
		color: #D26371 !important;
		border: 1upx solid #D26371 !important;
	}
	
	.inch{
		color: #F5A623 !important;
		border: 1upx solid #F5A623 !important;
	}
</style>
